package com.ruoyi.control.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.deviceControl.domain.DeviceControl;
import com.ruoyi.deviceControl.service.IDeviceControlService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备控制Controller
 * 
 * @author ruoyi
 * @date 2024-12-14
 */
@RestController
@RequestMapping("/deviceControl/deviceControl")
public class DeviceControlController extends BaseController
{
    @Autowired
    private IDeviceControlService deviceControlService;

    /**
     * 查询设备控制列表
     */
    @PreAuthorize("@ss.hasPermi('deviceControl:deviceControl:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceControl deviceControl)
    {
        startPage();
        List<DeviceControl> list = deviceControlService.selectDeviceControlList(deviceControl);
        return getDataTable(list);
    }

    /**
     * 导出设备控制列表
     */
    @PreAuthorize("@ss.hasPermi('deviceControl:deviceControl:export')")
    @Log(title = "设备控制", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceControl deviceControl)
    {
        List<DeviceControl> list = deviceControlService.selectDeviceControlList(deviceControl);
        ExcelUtil<DeviceControl> util = new ExcelUtil<DeviceControl>(DeviceControl.class);
        util.exportExcel(response, list, "设备控制数据");
    }

    /**
     * 获取设备控制详细信息
     */
    @PreAuthorize("@ss.hasPermi('deviceControl:deviceControl:query')")
    @GetMapping(value = "/{deviceControlId}")
    public AjaxResult getInfo(@PathVariable("deviceControlId") String deviceControlId)
    {
        return success(deviceControlService.selectDeviceControlByDeviceControlId(deviceControlId));
    }

    /**
     * 新增设备控制
     */
    @PreAuthorize("@ss.hasPermi('deviceControl:deviceControl:add')")
    @Log(title = "设备控制", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceControl deviceControl)
    {
        return toAjax(deviceControlService.insertDeviceControl(deviceControl));
    }

    /**
     * 修改设备控制
     */
    @PreAuthorize("@ss.hasPermi('deviceControl:deviceControl:edit')")
    @Log(title = "设备控制", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceControl deviceControl)
    {
        return toAjax(deviceControlService.updateDeviceControl(deviceControl));
    }

    /**
     * 删除设备控制
     */
    @PreAuthorize("@ss.hasPermi('deviceControl:deviceControl:remove')")
    @Log(title = "设备控制", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceControlIds}")
    public AjaxResult remove(@PathVariable String[] deviceControlIds)
    {
        return toAjax(deviceControlService.deleteDeviceControlByDeviceControlIds(deviceControlIds));
    }
}
